package cn.tedu.clyback.department.service.impl;


import cn.tedu.clyback.department.mapper.DepartmentMapper;
import cn.tedu.clyback.department.pojo.dto.DepartmentSaveParam;
import cn.tedu.clyback.department.pojo.dto.DepartmentSelectParam;
import cn.tedu.clyback.department.pojo.entity.Department;
import cn.tedu.clyback.department.pojo.vo.DepartmentVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class DepartmentServiceImpl implements cn.tedu.clyback.department.service.DepartmentService {
    @Autowired
    DepartmentMapper departmentMapper;
    @Override
    public List<DepartmentVO> selectDepartment(DepartmentSelectParam departmentSelectParam) {
        log.debug("开始处理【查询部门】的业务，参数：{}", departmentSelectParam);
        List<DepartmentVO> list = departmentMapper.selectDepartment(departmentSelectParam);
        log.debug("查询部门成功，结果：{}", list);
        return list;
    }

    @Override
    public void updateStatus(Integer departmentId, String status) {
        log.debug("开始处理【修改部门状态】的业务，参数：{},{}", departmentId, status);
        Department department = new Department();
        department.setDepartmentId(departmentId);
        department.setStatus(status);
        departmentMapper.updateStatus(department);
    }

    @Override
    public void deleteDepartment(Integer departmentId) {
        log.debug("开始处理【删除部门】的业务，参数：{}", departmentId);
        departmentMapper.deleteDepartment(departmentId);
    }

    @Override
    public void saveDepartment(DepartmentSaveParam departmentSaveParam) {
        log.debug("开始处理【添加部门】的业务，参数：{}", departmentSaveParam);
        Department department = new Department();
        BeanUtils.copyProperties(departmentSaveParam,department);
        if (departmentSaveParam.getDepartmentId()==null){
            department.setCreateTime(new Date());
            departmentMapper.insert(department);
        }else {
            departmentMapper.update(department);
        }


    }


}